package com.javaweb.demo.servlet;

import com.javaweb.demo.dao.UserDao;
import com.javaweb.demo.dao.UserDaolmpl;
import com.javaweb.demo.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

//@WebServlet(name = "SelectUserList" ,urlPatterns = "/SelectUserList")
public class SelectUserListServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        int id = request.getParameter("id") != null && !request.getParameter("id").equals("")? Integer.parseInt(request.getParameter("id")) : 0;
        String name = request.getParameter("name");
        String sex = request.getParameter("sex");
        String home = request.getParameter("home");
        UserDao ud = new UserDaolmpl();
        List<User> userSelect = ud.selectUser(id,name,sex,home);
        //System.out.println(name+"??"+userSelect.size());
        request.setAttribute("userSelect", userSelect);
        request.setAttribute("username", request.getParameter("username"));
        request.getRequestDispatcher("/SelectUserlist.jsp").forward(request, response);
    }
}
